`
https://leetcode.cn/problems/longest-palindromic-subsequence/
`

/**
 * @param {string} s
 * @return {number}
 */
var longestPalindromeSubseq = function (s) {
  // 可以转化为求和自己倒序序列的最长子序列
  // 直接复用 lcs 的代码即可
  // https://leetcode.cn/problems/longest-common-subsequence/
  return longestCommonSubsequence(s, s.split('').reverse().join(''))
};

var longestCommonSubsequence = function (text1, text2) {
  const m = text1.length, n = text2.length
  const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0))
  for (let i = 1; i <= m; i++) {
    for (let j = 1; j <= n; j++) {
      if (text1[i - 1] === text2[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1
      } else {
        dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1])
      }
    }
  }
  return dp[m][n]
};